home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Games of Daze
/
Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso
/
x2ftp
/
msdos
/
libs
/
knowhow4
/
kit.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1994-10-10
|
2KB
|
77 lines
#include "kit.h"
Kit::Kit()
{
size = DELTA;
current = used = 0;
list = (Visible**)malloc((size) * sizeof(Visible*));
list[0] = 0;
help_context = 0;
}
///////////////////////////
Kit::~Kit()
{
delete help_context;
for(int n = used; n >= 0; n--) // iterates through container
{ // and tests if pointer is
if(list[n] != NULL) // unique - deletes it
{
for(int i = n - 1; i >= 0; i--)
{
if(list[n] == list[i])
list[i] = NULL;
}
delete list[n];
list[n] = NULL;
}
}
delete list;
}
/////////////////////////////////
void Kit::set_help_context(char* hName)
{
delete help_context;
help_context = strdup(hName);
}
//////////////////////////////
int Kit::get(Visible* obj)
{
for(int i = 0; list[i] != obj; i++)
;
return i;
}
/////////////////////////////
int Kit::add(Visible* object)
{
used++;
if(size < used)
list = (Visible**)realloc(list,
(size += DELTA) * sizeof(Visible*));
list[current = used] = object;
return current;
}
/////////////////////////////
Visible* Kit::remove(int number)
{
if(number > used)
return 0;
Visible* temp = list[number];
for(int i = number; i < used; i++)
list[i] = list[i + 1];
used--;
if(size - used > 2 * DELTA)
list = (Visible**)realloc(list,
(size -= DELTA) * sizeof(Visible*));
return temp;
}
////////////////////////////////
void Kit::insert(Visible* object, int number)
{
used++;
if(size < used)
list = (Visible**)realloc(list,
(size += DELTA) * sizeof(Visible*));
for(int i = used; i > number; i--)
list[i] = list[i - 1];
list[number] = object;
}